package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Classname PayWebController
 * @Description 整个支付流程可以参考文档：https://opendocs.alipay.com/open/270/105899
 * @Date 2021/10/21 13:57
 * @Author Anonymous
 */
@Controller
@SuppressWarnings("all")
public class PayWebController {

    @Resource
    private AlipayTemplate alipayTemplate;

    @Resource
    private OrderService orderService;

    @ResponseBody
    @RequestMapping(value = "/payOrder",produces = "text/html")  //如果是json:"application/json",produces的作用就是告诉SpringMVC返回的类型是html
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo);
//        System.out.println(pay);测试时候发现这里返回的是一个页面，也就是支付页面的html
        return pay;
    }
}
